#include "playscene.h"
#include <QDebug>
#include <QMenuBar>
#include <QPainter>
#include <QTimer>
#include <QLabel>
#include "mypushbutton.h"
#include "coin.h"


PlayScene::PlayScene(int index)
{
    this->levelIndex=index;
    qDebug()<<"您进入的是第"<<this->levelIndex<<"关";

    this->setFixedSize(320,588);//设置窗口尺寸
    this->setWindowTitle("翻金币场景~");//设置标题
    this->setWindowIcon(QIcon(":/resource/Coin0001.png")); //设置图标

    //创建菜单栏
    QMenuBar * bar = menuBar();
    this->setMenuBar(bar);
    QMenu * startMenu = bar->addMenu("开始"); //创建菜单
    QAction * quitAction = startMenu->addAction("退出");//创建菜单“退出”项；
    connect(quitAction,&QAction::triggered,[=](){
        this->close();
    });//监听退出


    //返回按钮
       MyPushButton * backBtn = new MyPushButton(":/resource/BackButton.png",":/resource/BackButtonSelected.png");
       backBtn->setParent(this);
       backBtn->move(this->width()-backBtn->width(),this->height()-backBtn->height());

       connect(backBtn,&MyPushButton::clicked,[=](){
        //qDebug()<<"RETURN";

       QTimer::singleShot(500,this,[=](){
            emit this->ChooseSceneBack();//延时 发送点击返回的signals
        });
      });

       //显示当前关卡号
       QLabel * label = new QLabel;
       label->setParent(this);
       QString str = QString("Level: %1").arg(this->levelIndex);//初始化字符串
       label->setText(str);
       QFont font("华文新魏",20);
       label->setFont(font);
       //设置label的大小和位置
       label->setFixedSize(backBtn->width(),backBtn->height());
       label->move(30,this->height()-50);
       label->setGeometry(QRect(30,this->height()-50,this->width(),50));
       //设置属性
       label->setAttribute(Qt::WA_TransparentForMouseEvents);

       //创建金币的背景图片
        for(int i=0;i<4;i++){
           for(int j=0;j<4;j++){
               QLabel * label = new QLabel;
               QPixmap pix;
               pix.load(":/resource/BoardNode.png");
               label->setGeometry(0,0,pix.width(),pix.height());
               label->setPixmap(pix);
               label->setParent(this);
               label->move(57+i*pix.width(),200+j*pix.height());

               //创建金币
               Coin * coin = new Coin(":/resource/Coin0001.png");
               coin->setParent(this);
               coin->move(59+i*pix.width(),204+j*pix.height());
           }
       }

}



void PlayScene::paintEvent(QPaintEvent *)//第三个场景
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/resource/OtherSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    pix.load(":/resource/Title.png");
    pix = pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix);
}


